home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MultiSession 1.04 Source / Core 27⁄June⁄1993 / CViewRect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-27  |  9.1 KB  |  371 lines  |  [TEXT/KAHL]

  1. /* CViewRect.c */
  2.  
  3. #include "CViewRect.h"
  4. #include "CWindow.h"
  5. #include "CEnclosure.h"
  6.  
  7.  
  8. /* */        CViewRect::~CViewRect()
  9.     {
  10.         ERROR(Initialized != True,PRERR(ForceAbort,
  11.             "CViewRect::~CViewRect called on uninitialized object."));
  12.         if (KeyReceiverViewRect == this) {KeyReceiverViewRect = NIL;}
  13.         if (LastKeyDownViewRect == this) {LastKeyDownViewRect = NIL;}
  14.         if (LastMouseDownViewRect == this) {LastMouseDownViewRect = NIL;}
  15.         if (Enclosure != NIL)
  16.             {
  17.                 Enclosure->DeregisterViewRect(this);
  18.             }
  19.         if ((Window != this) && (Window != NIL)) /* filter the two bad possibilities */
  20.             {
  21.                 /* i.e. don't do this if we are the window. */
  22.                 SetUpPort();
  23.                 Window->InvalidateLong(ZeroPoint,Extent);
  24.                 Window->DeregisterClient(this);
  25.             }
  26.     }
  27.  
  28.  
  29. /* */        CViewRect::CViewRect()
  30.     {
  31.         EXECUTE(Initialized = False;)
  32.         MyCursor = arrow;
  33.         SetStickiness(LeftEdgeStatic,TopEdgeStatic,WidthStatic,HeightStatic);
  34.         Enabled = True;
  35.         Suspended = True;
  36.     }
  37.  
  38.  
  39. void        CViewRect::IViewRect(LongPoint TheOrigin, LongPoint TheExtent,
  40.                     CWindow* TheWindow, CEnclosure* TheEnclosure)
  41.     {
  42.         ERROR(Initialized == True,PRERR(ForceAbort,
  43.             "CViewRect::IViewRect called on already initialized object."));
  44.         EXECUTE(Initialized = True);
  45.         Start = TheOrigin;
  46.         Extent = TheExtent;
  47.         Window = TheWindow;
  48.         ERROR(TheWindow==NIL,PRERR(ForceAbort,
  49.             "CViewRect::IViewRect passed NIL for a window."));
  50.         Enclosure = TheEnclosure;
  51.         if (TheEnclosure != NIL)
  52.             {
  53.                 /* this means it is NOT a window (only windows don't have enclosures) */
  54.                 TheEnclosure->RegisterViewRect(this);
  55.                 RecalcLocsInitial();
  56.                 TheWindow->RegisterClient(this);
  57.             }
  58.     }
  59.  
  60.  
  61. void            CViewRect::DoMouseDown(MyEventRec Event)
  62.     {
  63.         ERROR(Initialized != True,PRERR(ForceAbort,
  64.             "CViewRect::DoMouseDown called on uninitialized object."));
  65.     }
  66.  
  67.  
  68. void            CViewRect::DoMouseUp(MyEventRec Event)
  69.     {
  70.         ERROR(Initialized != True,PRERR(ForceAbort,
  71.             "CViewRect::DoMouseUp called on uninitialized object."));
  72.     }
  73.  
  74.  
  75. MyBoolean    CViewRect::DoKeyDown(MyEventRec Event)
  76.     {
  77.         ERROR(Initialized != True,PRERR(ForceAbort,
  78.             "CViewRect::DoKeyDown called on uninitialized object."));
  79.         return False;
  80.     }
  81.  
  82.  
  83. void            CViewRect::DoKeyUp(MyEventRec Event)
  84.     {
  85.         ERROR(Initialized != True,PRERR(ForceAbort,
  86.             "CViewRect::DoKeyUp called on uninitialized object."));
  87.     }
  88.  
  89.  
  90. MyBoolean    CViewRect::DoMouseMoved(MyEventRec Event)
  91.     {
  92.         SetCursor(&MyCursor);
  93.         return True;
  94.     }
  95.  
  96.  
  97. void            CViewRect::DoUpdate(void)
  98.     {
  99.         ERROR(Initialized != True,PRERR(ForceAbort,
  100.             "CViewRect::DoUpdate called on uninitialized object."));
  101.     }
  102.  
  103.  
  104. /* this is when the window ceases to be active */
  105. void            CViewRect::DoSuspend(void)
  106.     {
  107.         ERROR(Initialized != True,PRERR(ForceAbort,
  108.             "CViewRect::DoSuspend called on uninitialized object."));
  109.         ERROR(Suspended,PRERR(ForceAbort,
  110.             "CViewRect::DoSuspend called on a suspended object."));
  111.         if ((KeyReceiverViewRect != this) || ((KeyReceiverViewRect == this)
  112.             && (RelinquishKeyReceivership())))
  113.             {
  114.                 Suspended = True;
  115.             }
  116.     }
  117.  
  118.  
  119. /* this is when the window again becomes active */
  120. void            CViewRect::DoResume(void)
  121.     {
  122.         ERROR(Initialized != True,PRERR(ForceAbort,
  123.             "CViewRect::DoResume called on uninitialized object."));
  124.         ERROR(!Suspended,PRERR(ForceAbort,
  125.             "CViewRect::DoResume called on an object that isn't suspended."));
  126.         Suspended = False;
  127.     }
  128.  
  129.  
  130. /* this is when the object becomes disabled */
  131. void            CViewRect::DoDisable(void)
  132.     {
  133.         ERROR(Initialized != True,PRERR(ForceAbort,
  134.             "CViewRect::DoDisable called on uninitialized object."));
  135.         if ((KeyReceiverViewRect != this) || ((KeyReceiverViewRect == this)
  136.             && (RelinquishKeyReceivership())))
  137.             {
  138.                 Enabled = False;
  139.             }
  140.     }
  141.  
  142.  
  143. /* this is when the object becomes enabled */
  144. void            CViewRect::DoEnable(void)
  145.     {
  146.         ERROR(Initialized != True,PRERR(ForceAbort,
  147.             "CViewRect::DoEnable called on uninitialized object."));
  148.         Enabled = True;
  149.     }
  150.  
  151.  
  152. MyBoolean    CViewRect::BecomeKeyReceiver(void)
  153.     {
  154.         ERROR(Initialized != True,PRERR(ForceAbort,
  155.             "CViewRect::BecomeKeyReceiver called on uninitialized object."));
  156.         if (ActiveWindow != Window)
  157.             {
  158.                 EXECUTE(PRERR(AllowResume,"CViewRect::BecomeKeyReceiver called when object's "
  159.                     "window was not the active window."));
  160.                 return False;
  161.             }
  162.          else
  163.             {
  164.                 if (KeyReceiverViewRect != this)
  165.                     {
  166.                         if ((KeyReceiverViewRect == NIL) || ((KeyReceiverViewRect != NIL)
  167.                             && (KeyReceiverViewRect->RelinquishKeyReceivership())))
  168.                             {
  169.                                 KeyReceiverViewRect = this;
  170.                                 return True;
  171.                             }
  172.                          else
  173.                             {
  174.                                 return False;
  175.                             }
  176.                     }
  177.                  else
  178.                     {
  179.                         return False; /* if we already are, we can't become */
  180.                     }
  181.             }
  182.     }
  183.  
  184.  
  185. MyBoolean    CViewRect::RelinquishKeyReceivership(void)
  186.     {
  187.         ERROR(Initialized != True,PRERR(ForceAbort,
  188.             "CViewRect::RelinquishKeyReceivership called on uninitialized object."));
  189.         ERROR(KeyReceiverViewRect != this,PRERR(ForceAbort,
  190.             "CViewRect::RelinquishKeyReceivership sent to object that isn't a key Receiver."));
  191.         KeyReceiverViewRect = NIL;
  192.         return True;
  193.     }
  194.  
  195.  
  196. MyBoolean    CViewRect::DoMenuCommand(ushort MenuCommandValue)
  197.     {
  198.         ERROR(Initialized != True,PRERR(ForceAbort,
  199.             "CViewRect::DoMenuCommand called on uninitialized object."));
  200.         return False;
  201.     }
  202.  
  203.  
  204. /* enable the menu items this object can handle */
  205. void            CViewRect::EnableMenuItems(void)
  206.     {
  207.         ERROR(Initialized != True,PRERR(ForceAbort,
  208.             "CViewRect::EnableMenuItems called on uninitialized object."));
  209.     }
  210.  
  211.  
  212. /* recalculate the visible rectangle and origin */
  213. void            CViewRect::RecalcLocations(LongPoint EnclosureVisRectStart,
  214.                         LongPoint EnclosureVisRectExtent, LongPoint EnclosureOrigin)
  215.     {
  216.         ERROR(Initialized != True,PRERR(ForceAbort,
  217.             "CViewRect::RecalcLocations called on uninitialized object."));
  218.         Origin.x = Start.x + EnclosureOrigin.x;
  219.         Origin.y = Start.y + EnclosureOrigin.y;
  220.         SectLongRect(EnclosureVisRectStart,EnclosureVisRectExtent,Origin,Extent,
  221.             &VisRectStart,&VisRectExtent);
  222.     }
  223.  
  224.  
  225. /* this is called when object is first created.  it allows things such as scrolling */
  226. /* views to wait for their contents to be initialized before recalcing */
  227. void            CViewRect::RecalcLocsInitial(void)
  228.     {
  229.         ERROR(Initialized != True,PRERR(ForceAbort,
  230.             "CViewRect::RecalcLocsInitial called on uninitialized object."));
  231.         RecalcLocations(Enclosure->VisRectStart,Enclosure->VisRectExtent,Enclosure->Origin);
  232.     }
  233.  
  234.  
  235. /* set up the window for our drawing environment */
  236. void            CViewRect::SetUpPort(void)
  237.     {
  238.         ERROR(Initialized != True,PRERR(ForceAbort,
  239.             "CViewRect::SetUpPort called on uninitialized object."));
  240.         ERROR(Window==NIL,PRERR(ForceAbort,
  241.             "CViewRect::SetUpPort called, but Window is NIL."));
  242.         Window->SetMyPort();
  243.         Window->SetOrigin(Origin);
  244.         Window->SetClipRect(ZeroPoint,Extent);
  245.     }
  246.  
  247.  
  248. LongPoint    CViewRect::MyGlobalToLocal(LongPoint GlobalPoint)
  249.     {
  250.         ERROR(Initialized != True,PRERR(ForceAbort,
  251.             "CViewRect::MyGlobalToLocal called on uninitialized object."));
  252.         ERROR(Window==NIL,PRERR(ForceAbort,
  253.             "CViewRect::MyGlobalToLocal called, but Window is NIL."));
  254.         GlobalPoint.x = GlobalPoint.x - Window->Start.x - Origin.x;
  255.         GlobalPoint.y = GlobalPoint.y - Window->Start.y - Origin.y;
  256.         return GlobalPoint;
  257.     }
  258.  
  259.  
  260. long            CViewRect::Hook(short OperationID, long Operand1, long Operand2)
  261.     {
  262.         return 0;
  263.     }
  264.  
  265.  
  266. void            CViewRect::SetStickiness(short Left, short Top, short Width, short Height)
  267.     {
  268.         WidthResizeMode = Width;
  269.         HeightResizeMode = Height;
  270.         LeftMoveMode = Left;
  271.         TopMoveMode = Top;
  272.     }
  273.  
  274.  
  275. void            CViewRect::DoEnclosureResized(LongPoint EnclosureAdjust)
  276.     {
  277.         long            LeftAdjust;
  278.         long            TopAdjust;
  279.         long            WidthAdjust;
  280.         long            HeightAdjust;
  281.  
  282.         ERROR(Initialized != True,PRERR(ForceAbort,
  283.             "CViewRect::DoEnclosureResized called on uninitialized object."));
  284.         /* invalidate where we are [soon to be were] */
  285.         SetUpPort();
  286.         Window->InvalidateLong(ZeroPoint,Extent);
  287.  
  288.         switch (LeftMoveMode)
  289.             {
  290.                 case LeftEdgeStatic:
  291.                     LeftAdjust = 0;
  292.                     break;
  293.                 case LeftEdgeSticky:
  294.                     LeftAdjust = EnclosureAdjust.x;
  295.                     break;
  296.                 case LeftEdgeCustom:
  297.                     LeftAdjust = CustomLeftMove();
  298.                     break;
  299.             }
  300.         switch (WidthResizeMode)
  301.             {
  302.                 case WidthStatic:
  303.                     WidthAdjust = 0;
  304.                     break;
  305.                 case WidthSticky:
  306.                     WidthAdjust = EnclosureAdjust.x;
  307.                     break;
  308.                 case WidthCustom:
  309.                     WidthAdjust = CustomWidthChange();
  310.                     break;
  311.             }
  312.         switch (TopMoveMode)
  313.             {
  314.                 case TopEdgeStatic:
  315.                     TopAdjust = 0;
  316.                     break;
  317.                 case TopEdgeSticky:
  318.                     TopAdjust = EnclosureAdjust.y;
  319.                     break;
  320.                 case TopEdgeCustom:
  321.                     TopAdjust = CustomTopMove();
  322.                     break;
  323.             }
  324.         switch (HeightResizeMode)
  325.             {
  326.                 case HeightStatic:
  327.                     HeightAdjust = 0;
  328.                     break;
  329.                 case HeightSticky:
  330.                     HeightAdjust = EnclosureAdjust.y;
  331.                     break;
  332.                 case HeightCustom:
  333.                     HeightAdjust = CustomHeightChange();
  334.                     break;
  335.             }
  336.         Start.x += LeftAdjust;
  337.         Start.y += TopAdjust;
  338.         Extent.x += WidthAdjust;
  339.         Extent.y += HeightAdjust;
  340.         RecalcLocations(Enclosure->VisRectStart,Enclosure->VisRectExtent,
  341.             Enclosure->Origin);
  342.  
  343.         /* invalidate where we moved to */
  344.         SetUpPort();
  345.         Window->InvalidateLong(ZeroPoint,Extent);
  346.     }
  347.  
  348.  
  349. long            CViewRect::CustomLeftMove(void)
  350.     {
  351.         return 0;
  352.     }
  353.  
  354.  
  355. long            CViewRect::CustomTopMove(void)
  356.     {
  357.         return 0;
  358.     }
  359.  
  360.  
  361. long            CViewRect::CustomWidthChange(void)
  362.     {
  363.         return 0;
  364.     }
  365.  
  366.  
  367. long            CViewRect::CustomHeightChange(void)
  368.     {
  369.         return 0;
  370.     }
  371.